package com.dlkw.easyroom;

import java.lang.reflect.Method;
import java.util.function.Function;

/**
 * 支持提取 Lambda 表达式的 Method 对象
 */
public interface SerializedLambdaGetter<T, R> extends Function<T, R> {
    /**
     * 获取 Lambda 表达式背后的方法对象
     */
    Method getMethod();

    /**
     * 包装普通 Function 为 SerializedLambdaGetter
     */
    static <T, R> SerializedLambdaGetter<T, R> wrap(final Function<T, R> function, final Method method) {
        return new SerializedLambdaGetter<T, R>() {
            @Override
            public R apply(T t) {
                return function.apply(t);
            }

            @Override
            public Method getMethod() {
                return method;
            }
        };
    }
}

